<extend name="Public/base"/>
<block name="body">

    <div style="margin: 0px auto;">
        <div class="wrapper wrapper-content animated fadeInRight" >

            <div class="row" >

                <div class="col-sm-6">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5>添加分组</h5>

                        </div>
                        <div class="ibox-content">
                            <form class="form-horizontal m-t"  action="{:U()}" method="post" onsubmit="return chkform2(this)">

                                <div class="form-group">
                                    <label class="col-sm-3 control-label">分组名称：</label>
                                    <div class="col-sm-8">
                                        <input id="group_name" name="group_name" class="form-control" type="text" required="" value="{$group.group_name}">
                                        <input type="hidden" name="id" value="{$group.id}">
                                    </div>
                                </div>



                                <div class="form-group">
                                    <label class="col-sm-3 control-label">分组状态：</label>
                                    <div class="col-sm-8"><select class="form-control m-b" name="status">
                                        <option value="0"><font color="#32cd32">正常</font></option>
                                        <option value="1"><font color="red">禁用</font></option>
                                    </select>
                                    </div>
                                </div>

                                <hr>
                                <label >分配权限</label>
                                <table border="1px solid black" width="100%">
                                    <volist name='menu' id='menu'>

                                        <tr>
                                            <td style="text-align:left;margin-left: 10px;"><input name="rules[]" type="checkbox" value="{$menu.id}" />{$menu.menu_name}</td>
                                            <td style="text-align:left;">
                                                <volist name="menu.child" id="child">
                                                    <input name="rules[]" type="checkbox" value="{$child.id}" />{$child.menu_name}
                                                </volist>
                                            </td>

                                        </tr>
                                    </volist>
                                </table>

                                <hr>



                                <div class="form-group">
                                    <div class="col-sm-8 col-sm-offset-3">
                                        <button class="btn btn-primary" type="submit">提交</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        $('#1').attr('class','active');

        $("#status option[value='{$group.status}']").attr("selected", "selected");
        var rules = eval('('+'{$rules}'+')');
        function contains(arr, obj) {
            var i = arr.length;
            while (i--) {
                if (arr[i] == obj) {
                    return true;
                }
            }
            return false;
        }
        $("input[name='rules[]']").each(function(e){
            if(contains(rules,$(this).val()) == true){
                $(this).attr('checked',true);
            }
        });
    </script>
</block>